/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * finDiffEvalAndChkErr.c
 *
 * Code generation for function 'finDiffEvalAndChkErr'
 *
 */

/* Include files */
#include "finDiffEvalAndChkErr.h"
#include "Modalmass_estimation_newchangefinal1219_rtwutil.h"
#include "rt_nonfinite.h"
#include "rt_nonfinite.h"
#include <math.h>

/* Function Definitions */
boolean_T finDiffEvalAndChkErr(const double c_obj_nonlin_workspace_fun_work[3],
                               double cEqPlus[4], int dim, double delta,
                               double xk[4], double *fplus)
{
  double d;
  double d1;
  double d2;
  double d3;
  double d4;
  double d5;
  double d6;
  double d7;
  double temp_tmp;
  int idx;
  boolean_T evalOK;
  *fplus = 0.0;
  evalOK = true;
  temp_tmp = xk[dim - 1];
  xk[dim - 1] = temp_tmp + delta;
  /*  确保 F 是 1x4 实数数组 */
  /*  T2/T1 输入 */
  /*  T3/T1 输入 */
  d = xk[3] * xk[3];
  d1 = xk[0] * xk[0];
  d2 = d1 + d;
  d3 = xk[1] * xk[1];
  d4 = d3 + d;
  cEqPlus[0] =
      c_obj_nonlin_workspace_fun_work[0] / c_obj_nonlin_workspace_fun_work[1] -
      xk[0] / xk[1] * sqrt(d2 / d4);
  d5 = xk[2] * xk[2];
  cEqPlus[1] =
      c_obj_nonlin_workspace_fun_work[0] / c_obj_nonlin_workspace_fun_work[2] -
      xk[0] / xk[2] * sqrt(d2 / (d5 + d));
  d6 = sqrt(d2);
  d7 = rt_powd_snf(xk[3], 4.0);
  cEqPlus[2] = ((d7 / d1 / d2 + 2.0) * cos(xk[0]) * cosh(d6) + 2.0) +
               d5 / xk[0] / d6 * sin(xk[0]) * sinh(d6);
  d1 = sqrt(d4);
  cEqPlus[3] = ((d7 / d3 / d4 + 2.0) * cos(xk[1]) * cosh(d1) + 2.0) +
               d / xk[1] / d1 * sin(xk[1]) * sinh(d1);
  idx = 0;
  while (evalOK && (idx + 1 <= 4)) {
    evalOK = ((!rtIsInf(cEqPlus[idx])) && (!rtIsNaN(cEqPlus[idx])));
    idx++;
  }
  xk[dim - 1] = temp_tmp;
  return evalOK;
}

/* End of code generation (finDiffEvalAndChkErr.c) */
